package com.crimerank;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.os.Bundle;

public class BaseActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	protected String doHttpRequest(String url, String query) {
		String response = "";
		HttpURLConnection connection = null;
		BufferedReader reader = null;

		try {
			// Open HTTP connection to the server
			URL transit_server = new URL(url + "?" + query);
			connection = (HttpURLConnection) transit_server.openConnection();
			connection.setRequestProperty("Accept-Charset", "UTF-8");

			// Read the response from HTTP request
			reader = new BufferedReader(new InputStreamReader(
					connection.getInputStream()));
			for (String line; (line = reader.readLine()) != null;) {
				response += line;
			}

		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (connection != null) {
				connection.disconnect();
			}
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e) {
				}
			}
		}

		return response;
	}
}
